<?php 
#############################################################################
#  Module Mini Webboard for Opencart 1.4.8 Up  From Team SiamOpencart.com		  											   #
#  เว็บผู้พัฒนา www.siamopencart.com ,www.thaiopencart.com                                                                                 #
#  โดย Somsak2004 วันที่ 23 พฤศจิกายน 2553                                                                                                           #
#############################################################################
# โดยการสนับสนุนจาก                                                                                                                                            #
# Unitedsme.com : ผู้ให้บริการเช่าพื้นที่เว็บไซต์ จดโดเมน ระบบ Linux                                                                              #
# Net-LifeStyle.com : ผู้ให้บริการเช่าพื้นที่เว็บไซต์์ จดโดเมน ระบบ Linux																           #
# SiamWebThai.com : SEO ขั้นเทพ โปรโมทเว็บขั้นเซียน ออกแบบ พัฒนาเว็บไซต์ / ตามความต้องการ และถูกใจ Google 		   #
#############################################################################
class ControllerModuleWebboard extends Controller {
	private $act;
	private $data_ask=array();
	private $ask_new=array();
	public function index() {  
    	$this->language->load('webboard/board');

       // $this->document->title = $this->language->get('heading_title');  
	
		$this->load->model('webboard/webboard');
		
		$this->document->breadcrumbs = array();
		
      	$this->document->breadcrumbs[] = array(
        	'href'      => (HTTP_SERVER . 'index.php?route=common/home'),
        	'text'      => $this->language->get('text_home'),
        	'separator' => FALSE
      	);
		
    	    $this->data['heading_title'] = $this->language->get('heading_title');
      		$this->data['text_title'] = $this->language->get('text_title');
      		$this->data['text_order'] = $this->language->get('text_order');
      		$this->data['text_title_board'] = $this->language->get('text_title_board');
      		$this->data['text_read'] = $this->language->get('text_read');
      		$this->data['text_reply'] = $this->language->get('text_reply');
      		$this->data['text_date'] = $this->language->get('text_date');
      		$this->data['text_author'] = $this->language->get('text_author');
      		$this->data['text_delete'] = $this->language->get('text_delete');
      		$this->data['text_mark'] = $this->language->get('text_mark');
      		$this->data['text_newpost'] = $this->language->get('text_newpost');
      		$this->data['text_newpost_alert'] = $this->language->get('text_newpost_alert');
      		$this->data['alert'] = $this->language->get('alert');

			$this->data['nameboard'] = html_entity_decode($this->config->get('webboard_name'));
			$this->data['webboard_guest'] = html_entity_decode($this->config->get('webboard_guest'));
			$this->data['webboard_day'] = html_entity_decode($this->config->get('webboard_day'));

			$this->data['register_user']=html_entity_decode($this->customer->isLogged());
			if (isset($_SESSION['user_id'])) {$this->data['admin']=$_SESSION['user_id'];}else{$this->data['admin']=null;}

  			if($this->config->get('webboard_name') != "" && $this->config->get('webboard_position') == 'home' ) {
		 	   $this->data['heading_title'] = $this->config->get('webboard_name');
			}

		//webboard
		$this->data['webboard_show'] = $this->language->get('webboard_show');
		$this->data['text_title'] = $this->language->get('text_title');
		$this->data['text_date'] = $this->language->get('text_date');
		$this->data['text_author'] = $this->language->get('text_author');
		$this->load->model('webboard/webboard');
		$this->data['webboard_show_limit'] = html_entity_decode($this->config->get('webboard_show_limit'));
		$this->data['webboard_day'] =html_entity_decode($this->config->get('webboard_day'));
		$this->data_ask	= $this->model_webboard_webboard->ShowUpdate($this->config->get('webboard_show_limit'));
		foreach ($this->data_ask as $ask){
				     $this->ask_new[]=array(
				    'number_reply'    => $this->model_webboard_webboard->getQuessBoardNumber($ask['ask_id']),
          			'author'         => $ask['author'],
          			'ask_id' => $ask['ask_id'],
          			'title' => $ask['title'],
          			'detail' => $ask['detail'],
          			'date' => $ask['date'],
          			'counter' => $ask['counter'],
					'new' => floor((strtotime("now")	- strtotime($ask['date']))/(3600*24)	),
					'new_reply'=> $this->model_webboard_webboard->CheckDateOfQuess($ask['ask_id'])
					 );
		}
		 $this->data['show_board'] = $this->ask_new;
		//webboard


     		/*
			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/webboard/board.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/webboard/board.tpl';
			} else {
				$this->template = 'default/template/webboard/board.tpl';
			}


			
			$this->children = array(
				'common/header',
				'common/footer',
				'common/column_left',
				'common/column_right'
			);		
			
			*/


   			if (isset($this->request->get['page'])) {
				$page = $this->request->get['page'];
			} else { 
				$page = 1;
			}	
   			if (isset($this->request->get['id'])) {
				$id = $this->request->get['id'];
			} 
   			if (isset($this->request->get['act'])) {
				$this->act = $this->request->get['act'];
			} 
			$this->data['page'] = $page;

		   if ($this->act=="delete") {
			$this->model_webboard_webboard->DeleteTopic($id) ;
			$redirect=$this->redirect((HTTPS_SERVER . 'index.php?route=webboard/board&page='.$page)); 
		   }


				$pagination = new Pagination();
				$pagination->total =  $this->model_webboard_webboard->getAllBoard();
				$pagination->page = $page;
				$pagination->limit = html_entity_decode($this->config->get('webboard_num_show'));  //กำหนดจำนวนแสดงต่อหน้า
				$pagination->text = $this->language->get('text_pagination');
				$pagination->url = (HTTP_SERVER . 'index.php?route=webboard/board&page='.$page);
 				$this->data['pagination'] = $pagination->render();
	     	    $this->data['continue'] = (HTTP_SERVER . 'index.php?route=common/home');

			   $this->data_ask=$this->model_webboard_webboard->getAskPost($page,$pagination->limit);
				foreach ($this->data_ask as $ask){
				      $this->ask_new[]=array(
				    'number_reply'    => $this->model_webboard_webboard->getQuessBoardNumber($ask['ask_id']),
          			'author'         => $ask['author'],
          			'ask_id' => $ask['ask_id'],
          			'title' => $ask['title'],
          			'detail' => $ask['detail'],
          			'date' => $ask['date'],
          			'counter' => $ask['counter'],
					'new' => floor((strtotime("now")	- strtotime($ask['date']))/(3600*24)	),
					'new_reply'=> $this->model_webboard_webboard->CheckDateOfQuess($ask['ask_id'])
					 );
				}
			$this->data['ask'] = $this->ask_new;

		$this->id = 'webboard';


		if ($this->config->get('webboard_position') == 'home') {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/webboard/board_home.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/webboard/board_home.tpl';
			} else {
				$this->template = 'default/template/module/board_home.tpl';
			}
		} else {
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/webboard/board_side.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/webboard/board_side.tpl';
			} else {
				$this->template = 'default/template/module/board_side.tpl';
			}
		}
	  		$this->render();
  	}
}
?>